#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
int isprime(int i)
{
    if (i <= 1)
        return 0;
    if (i == 2)
        return 1;
    for (int t = 2; t <= sqrt(i); t++)
    {
        if (i % t == 0)
            return 0;
    }
    return 1;
}
int main()
{
    int n = 0, m = 0;
    scanf("%d%d", &n, &m);
    int count = 0;
    for (int i = m; i <= n; i++)
    {
        if (isprime(i))
        {
            count++;
        }
    }
    int arr[count];
    int num = 0;
    for (int a = m; a <= n; a++)
    {
        if (isprime(a))
        {
            arr[num] = a;
            num++;
        }
    }
    int f = 0;
    for (int b = 0; b < count - 2; b++)
    {
        for (int c = b + 1; c < count - 1; c++)
        {
            for (int d = c + 1; d < count; d++)
            {
                if (isprime(arr[b] * arr[c] + arr[d]) && isprime(arr[b] * arr[d] + arr[c]) && isprime(arr[c] * arr[d] + arr[b]))
                    f++;
            }
        }
    }
    printf("%d", f);
    return 0;
}